package cn.south.campus.admin.campus.service.impl;

import cn.south.campus.admin.campus.mapper.StudentMapper;
import cn.south.campus.admin.campus.model.entity.Student;
import cn.south.campus.admin.campus.model.req.AuditReq;
import cn.south.campus.admin.campus.model.vo.StudentVo;
import cn.south.campus.admin.campus.service.StudentService;
import cn.south.campus.common.model.enums.CommonEnums;
import cn.south.campus.common.utils.AssertUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 学生认证表 服务实现类
 * </p>
 *
 * @author chow
 * @since 2024-11-13
 */
@Service
@AllArgsConstructor
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    private StudentMapper studentMapper;

    @Override
    public StudentVo getAuth(Long userId) {
        LambdaQueryWrapper<Student> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Student::getUserId,userId);
        Student student = studentMapper.selectOne(wrapper);
        return StudentVo.convert(student);
    }

    @Override
    public void audit(AuditReq req) {
        Long id = req.getId();
        Integer status = req.getStatus();
        Student student = studentMapper.selectById(id);
        AssertUtils.isNotNull(student, CommonEnums.DATA_HAS_NOT_ERROR);
        student.setStatus(status);
        studentMapper.updateById(student);
    }
}
